package com.iotimc.attendancesystem.activity;


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

/**
 * This view is overlaid on top of the camera preview. It adds the viewfinder
 * rectangle and partial transparency outside it, as well as the laser scanner
 * animation and result points.
 */
public final class ViewfinderView extends View {
	private static final String TAG = "ViewfinderView";
	private static final int OPAQUE = 0xFF;
	/**
	 * 画笔对象的引用,mLinePaint画中间线框，mAreaPaint画周围半透明阴影部分
	 */
	private Paint mAreaPaint;
	//private final int maskColor;
	//private  int resultColor;
	private Rect frameRect;
	private int lineColor;

	public ViewfinderView(Context context, AttributeSet attrs) {
		super(context, attrs);
		mAreaPaint = new Paint(Paint.ANTI_ALIAS_FLAG);  
		//Resources resources = getResources();
//		maskColor = resources.getColor(R.color.viewfinder_mask);
//		resultColor = resources.getColor(R.color.result_view);
		
//		TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ViewfinderView);
//        lineColor = ta.getInteger(R.styleable.ViewfinderView_lineColor, 1);
	}

	@Override
	public void onDraw(Canvas canvas) {
		//中间的扫描框，你要修改扫描框的大小，去CameraManager里面修改
		if (frameRect == null) {
			return;
		}
		

		mAreaPaint.setColor(lineColor);  
		mAreaPaint.setStyle(Style.STROKE);  
		mAreaPaint.setStrokeWidth(3f);  
		mAreaPaint.setAlpha(OPAQUE);  
		
	    canvas.drawRect(frameRect, mAreaPaint);
		
		super.onDraw(canvas); 
	}

	public void setFrameRect(Rect frameRect) {
		this.frameRect = frameRect;
		invalidate();  
	}
	
	
    public void clearFrameRect(){  
        this.frameRect = null;  
        invalidate();  
    }  
}
